package com.example.ljw.frescowallpaper.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.ljw.frescowallpaper.R;
import com.example.ljw.frescowallpaper.bean.SortBean;
import com.example.ljw.frescowallpaper.utils.RecyclerViewAdapterHelper;
import com.example.ljw.frescowallpaper.view.SortDetailActivity;

import java.util.List;

/**分类资源的适配器
 * Created by LJW on 2016/11/17.
 */

public class MySortAdapter extends RecyclerViewAdapterHelper<SortBean.ResBean.DataBean> {


    public MySortAdapter(Context context, List<SortBean.ResBean.DataBean> list) {

        super(context, list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view=mInflater.inflate(R.layout.item_sort_layout,parent,false);
        return new ViewHolder1(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        String imgUrl=mList.get(position).getCover();
        String textname=mList.get(position).getName();
        String textEname=mList.get(position).getEname();
        Log.e("TAG","imgurl"+imgUrl);
        ViewHolder1 viewHolder= (ViewHolder1) holder;
        viewHolder.tv_sort.setText(textname);
        viewHolder.tv2_sort.setText(textEname);
        Glide.with(mContext)
                .load(imgUrl)
                .placeholder(R.mipmap.wallpaper)
                .centerCrop()
                .into(viewHolder.imageView);

    }
    class  ViewHolder1 extends RecyclerView.ViewHolder implements View.OnClickListener{
        private ImageView imageView;
        private TextView tv_sort;
        private TextView tv2_sort;
        public ViewHolder1(View itemView) {
            super(itemView);
            tv_sort= (TextView) itemView.findViewById(R.id.tv_item_sort);
            tv2_sort= (TextView) itemView.findViewById(R.id.tv2_item_sort);
            imageView= (ImageView) itemView.findViewById(R.id.img_item_sort);
            imageView.setOnClickListener(this);

        }

        @Override
        public void onClick(View view) {
//            Toast.makeText(mContext, "1111"+mList.get(getAdapterPosition()).getCover(), Toast.LENGTH_SHORT).show();
            Intent intent=new Intent(mContext, SortDetailActivity.class);
            intent.putExtra("id",mList.get(getAdapterPosition()).getId());
            intent.putExtra("name",mList.get(getAdapterPosition()).getName());
            mContext.startActivity(intent);
        }
    }
}
